package com.arellomobile.android.push;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import com.arellomobile.android.push.utils.GeneralUtils;
import com.arellomobile.android.push.utils.PreferenceUtils;
import com.arellomobile.android.push.utils.notification.BannerNotificationFactory;
import com.arellomobile.android.push.utils.notification.BaseNotificationFactory;
import com.arellomobile.android.push.utils.notification.SimpleNotificationFactory;
import com.google.android.gcm.GCMBaseIntentService;
import java.util.Iterator;
import java.util.Set;
import org.json.JSONException;
import org.json.JSONObject;

public class PushGCMIntentService extends GCMBaseIntentService
{
  private static final String TAG = "GCMIntentService";
  private Handler mHandler;

  public PushGCMIntentService()
  {
    String str = PushManager.mSenderId;
    if (str == null)
      str = "";
    this.mSenderId = str;
    this.mHandler = new Handler();
  }

  private static void generateBroadcast(Context paramContext, Bundle paramBundle)
  {
    Intent localIntent = new Intent();
    localIntent.setAction(paramContext.getPackageName() + ".action.PUSH_MESSAGE_RECEIVE");
    localIntent.putExtras(paramBundle);
    JSONObject localJSONObject = new JSONObject();
    Iterator localIterator = paramBundle.keySet().iterator();
    while (true)
    {
      if (!localIterator.hasNext())
      {
        localIntent.putExtra("pw_data_json_string", localJSONObject.toString());
        paramContext.sendBroadcast(localIntent, paramContext.getPackageName() + ".permission.C2D_MESSAGE");
        return;
      }
      String str = (String)localIterator.next();
      if (str.equals("u"));
      try
      {
        localJSONObject.put("userdata", paramBundle.get("u"));
        try
        {
          label147: localJSONObject.put(str, paramBundle.get(str));
        }
        catch (JSONException localJSONException1)
        {
        }
      }
      catch (JSONException localJSONException2)
      {
        break label147;
      }
    }
  }

  private static void generateNotification(Context paramContext, Intent paramIntent, Handler paramHandler)
  {
    Bundle localBundle = paramIntent.getExtras();
    if (localBundle == null)
      return;
    localBundle.putBoolean("foregroud", GeneralUtils.isAppOnForeground(paramContext));
    boolean bool;
    String str1;
    String str2;
    Intent localIntent;
    label100: NotificationManager localNotificationManager;
    if (GeneralUtils.isAppOnForeground(paramContext))
    {
      bool = false;
      localBundle.putBoolean("onStart", bool);
      str1 = (String)localBundle.get("title");
      str2 = (String)localBundle.get("header");
      String str3 = (String)localBundle.get("l");
      if (str3 == null)
        break label308;
      localIntent = new Intent("android.intent.action.VIEW", Uri.parse(str3));
      localIntent.addFlags(268435456);
      if (str2 == null)
      {
        Object localObject2 = paramContext.getPackageManager().getApplicationLabel(paramContext.getApplicationInfo());
        if (localObject2 == null)
          localObject2 = "";
        str2 = ((CharSequence)localObject2).toString();
      }
      localNotificationManager = (NotificationManager)paramContext.getSystemService("notification");
      String str4 = (String)localBundle.get("b");
      if ((paramContext.getResources().getIdentifier("notification", "layout", paramContext.getPackageName()) == 0) || (str4 == null))
        break label343;
    }
    label308: label343: for (Object localObject1 = new BannerNotificationFactory(paramContext, localBundle, str2, str1, PreferenceUtils.getSoundType(paramContext), PreferenceUtils.getVibrateType(paramContext)); ; localObject1 = new SimpleNotificationFactory(paramContext, localBundle, str2, str1, PreferenceUtils.getSoundType(paramContext), PreferenceUtils.getVibrateType(paramContext)))
    {
      ((BaseNotificationFactory)localObject1).generateNotification();
      ((BaseNotificationFactory)localObject1).addSoundAndVibrate();
      ((BaseNotificationFactory)localObject1).addCancel();
      if (PreferenceUtils.getEnableLED(paramContext))
        ((BaseNotificationFactory)localObject1).addLED(true);
      Notification localNotification = ((BaseNotificationFactory)localObject1).getNotification();
      int i = PreferenceUtils.getMessageId(paramContext);
      if (PreferenceUtils.getMultiMode(paramContext))
      {
        i++;
        PreferenceUtils.setMessageId(paramContext, i);
      }
      localNotification.contentIntent = PendingIntent.getActivity(paramContext, i, localIntent, 134217728);
      localNotificationManager.notify(i, localNotification);
      generateBroadcast(paramContext, localBundle);
      DeviceFeature2_5.sendMessageDeliveryEvent(paramContext, localBundle.getString("p"));
      return;
      bool = true;
      break;
      localIntent = new Intent(paramContext, PushHandlerActivity.class);
      localIntent.addFlags(603979776);
      localIntent.putExtra("pushBundle", localBundle);
      break label100;
    }
  }

  protected void onDeletedMessages(Context paramContext, int paramInt)
  {
    Log.i("GCMIntentService", "Received deleted messages notification");
  }

  protected void onError(Context paramContext, String paramString)
  {
    Log.e("GCMIntentService", "Messaging registration error: " + paramString);
    PushEventsTransmitter.onRegisterError(paramContext, paramString);
  }

  protected void onMessage(Context paramContext, Intent paramIntent)
  {
    Log.i("GCMIntentService", "Received message");
    generateNotification(paramContext, paramIntent, this.mHandler);
  }

  protected boolean onRecoverableError(Context paramContext, String paramString)
  {
    Log.i("GCMIntentService", "Received recoverable error: " + paramString);
    return super.onRecoverableError(paramContext, paramString);
  }

  protected void onRegistered(Context paramContext, String paramString)
  {
    Log.i("GCMIntentService", "Device registered: regId = " + paramString);
    DeviceRegistrar.registerWithServer(paramContext, paramString);
  }

  protected void onUnregistered(Context paramContext, String paramString)
  {
    Log.i("GCMIntentService", "Device unregistered");
    DeviceRegistrar.unregisterWithServer(paramContext, paramString);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.arellomobile.android.push.PushGCMIntentService
 * JD-Core Version:    0.6.2
 */